package com.example.testdemo.demos.web.Controller;

import com.example.testdemo.demos.web.Dto.MessageDto;
import com.example.testdemo.demos.web.WebSocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author hanjinqun
 * @date 2022/10/24
 * websocket接口
 */

@Controller
@RequestMapping(value = "/message")
public class WebSocketController {
    @Autowired
    private WebSocketServer webSocketServer;

    /**
     * webSoket 群发消息
     * @param messageDTO
     * @return
     */
   @PostMapping("/sendAll")
    public Object sendTestMessage(@RequestBody MessageDto messageDTO) {
        try {
            webSocketServer.sendAllMessage(messageDTO.getContent());
        } catch (Exception e) {
            e.printStackTrace();
            return e;
        }
        return null;
    }

}
